package com.bwie.home.backstage.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.bwie.home.backstage.entity.vo.RankVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.bwie.home.backstage.entity.RankEntity;
import com.bwie.home.backstage.service.RankService;
import com.bwie.home.common.utils.PageUtils;
import com.bwie.home.common.utils.R;



/**
 * 
 *
 * @author sy
 * @email sunlightcs@gmail.com
 * @date 2021-09-16 18:44:30
 */
@RestController
@RequestMapping("backstage/rank")
public class RankController {
    @Autowired
    private RankService rankService;

    /**
     * 排行榜列表
     */
    @PostMapping("/getRank")
    public R getRank(@RequestBody RankVo rankVo){
        List<RankVo> rank = rankService.getRank(rankVo);
        return R.ok().put("list",rank);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = rankService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{rankId}")
    public R info(@PathVariable("rankId") Integer rankId){
		RankEntity rank = rankService.getById(rankId);

        return R.ok().put("rank", rank);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody RankEntity rank){
		rankService.save(rank);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody RankEntity rank){
		rankService.updateById(rank);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] rankIds){
		rankService.removeByIds(Arrays.asList(rankIds));

        return R.ok();
    }

}
